package o;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.application.pkgmanage.model.reserve.ReserveDbInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.card.gamereserve.bean.OrderAppCardBean;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.search.api.AutoCompleteBtnCardBean;
import com.huawei.appmarket.service.appmgr.view.activity.InstallManagerCardBean;
import com.huawei.appmarket.service.store.awk.bean.SafeAppCardBean;
import com.huawei.fastengine.fastview.FastSDKEngine;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import java.lang.ref.WeakReference;
import java.util.Locale;
import o.dkl.b;
import o.ewd.c;
import o.ewm.n;

public class dkd implements ckc {
    protected dwk ˊ = new dwk();
    protected Context ˋ;
    private ckb ˏ;

    static class a implements cks {
        private final DownloadButton ˋ;
        private final Context ˎ;
        private final BaseDistCardBean ˏ;

        private a(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean) {
            this.ˎ = context;
            this.ˋ = downloadButton;
            this.ˏ = baseDistCardBean;
        }

        public void enableNetworking() {
            new dkj().ˊ(this.ˎ, this.ˏ.ॱـ(), this.ˏ, new d(this.ˋ));
        }

        public void upgrade() {
        }

        public void ˋ() {
        }
    }

    static class d implements dkf {
        private WeakReference<DownloadButton> ˋ;

        private d(DownloadButton downloadButton) {
            this.ˋ = new WeakReference(downloadButton);
        }

        public void ˎ() {
            DownloadButton downloadButton = (DownloadButton) this.ˋ.get();
            if (downloadButton != null) {
                downloadButton.setEventProcessing(true);
                new Handler(Looper.getMainLooper()).post(new e(downloadButton, false));
            }
        }

        public void ॱ() {
            DownloadButton downloadButton = (DownloadButton) this.ˋ.get();
            if (downloadButton != null) {
                downloadButton.setEventProcessing(false);
                new Handler(Looper.getMainLooper()).post(new e(downloadButton, true));
            }
        }
    }

    static class e implements Runnable {
        private WeakReference<DownloadButton> ˋ;
        private boolean ˎ;

        private e(DownloadButton downloadButton, boolean z) {
            this.ˋ = new WeakReference(downloadButton);
            this.ˎ = z;
        }

        public void run() {
            DownloadButton downloadButton = (DownloadButton) this.ˋ.get();
            if (downloadButton != null) {
                downloadButton.setEnabled(this.ˎ);
            }
        }
    }

    public dkd(Context context) {
        this.ˋ = context;
    }

    private void ˏ(BaseDistCardBean baseDistCardBean) {
        ReserveDbInfo ॱ = efg.ˋ().ॱ(baseDistCardBean.ॱـ());
        if (ॱ != null) {
            if (!TextUtils.isEmpty(ॱ.ͺ())) {
                baseDistCardBean.ˏॱ(ॱ.ͺ());
                baseDistCardBean.ॱ(ॱ.ॱᐝ());
                baseDistCardBean.ˋॱ(ॱ.ॱˎ());
                baseDistCardBean.ˎ(ॱ.ॱˋ());
                baseDistCardBean.ॱᐝ(ॱ.ᐝॱ());
            }
            if (baseDistCardBean instanceof OrderAppCardBean) {
                ((OrderAppCardBean) baseDistCardBean).ˏॱ(1);
                ((OrderAppCardBean) baseDistCardBean).ʽ(ॱ.ˏॱ());
            }
        } else if (baseDistCardBean instanceof OrderAppCardBean) {
            ((OrderAppCardBean) baseDistCardBean).ˏॱ(0);
        }
    }

    public ckg ˎ(BaseDistCardBean baseDistCardBean) {
        if (ˊ(baseDistCardBean)) {
            return ˎ();
        }
        if (ॱ(baseDistCardBean)) {
            return ॱॱ(baseDistCardBean);
        }
        SessionDownloadTask ˎ;
        if (4 == baseDistCardBean.ͺ()) {
            ˏ(baseDistCardBean);
        }
        if (baseDistCardBean instanceof InstallManagerCardBean) {
            long ॱ = ((InstallManagerCardBean) baseDistCardBean).ॱ();
            if (ॱ > 0) {
                ˎ = dvt.ˏ().ˎ(ॱ);
                if (ˎ == null && baseDistCardBean.ॱـ() != null) {
                    ˎ = dvt.ˏ().ˎ(baseDistCardBean.ॱـ());
                }
                if (ˎ != null || (4 == baseDistCardBean.ͺ() && TextUtils.isEmpty(baseDistCardBean.ʾ()))) {
                    return ˋ(baseDistCardBean);
                }
                return ˊ(ˎ);
            }
        }
        ˎ = null;
        ˎ = dvt.ˏ().ˎ(baseDistCardBean.ॱـ());
        if (ˎ != null) {
        }
        return ˋ(baseDistCardBean);
    }

    public CharSequence ˋ(BaseDistCardBean baseDistCardBean, cke o_cke, CharSequence charSequence, TextView textView) {
        if ((o_cke == cke.DOWNLOAD_APP || o_cke == cke.UPGRADE_APP || o_cke == cke.SMART_UPGRADE_APP || o_cke == cke.OPEN_APP) && baseDistCardBean.ᐝॱ() && !ebz.ॱ().ˎ(baseDistCardBean.ॱـ()) && !TextUtils.isEmpty(baseDistCardBean.ॱˋ())) {
            charSequence = baseDistCardBean.ॱˋ();
        }
        return charSequence.toString().toUpperCase(Locale.getDefault());
    }

    public ckd ˋ() {
        return new dke();
    }

    public ckd ˎ(int i, int i2) {
        return new dke(this.ˋ, i, i2);
    }

    public void ˋ(DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        djx.ˋ(baseDistCardBean, o_cke, this.ˋ);
        ˎ(this.ˋ, downloadButton, baseDistCardBean, o_cke);
    }

    public void ˎ(ckb o_ckb) {
        this.ˏ = o_ckb;
    }

    @NonNull
    private ckg ˊ(SessionDownloadTask sessionDownloadTask) {
        String string;
        cke o_cke;
        int ʼॱ;
        ckg o_ckg = new ckg();
        switch (sessionDownloadTask.ˈ()) {
            case -1:
                string = this.ˋ.getResources().getString(n.ॱˊ);
                o_cke = cke.RESERVE_DOWNLOAD_APP;
                ʼॱ = sessionDownloadTask.ʼॱ();
                break;
            case 1:
            case 2:
            case 8:
                o_cke = cke.PAUSE_DOWNLOAD_APP;
                ʼॱ = sessionDownloadTask.ʼॱ();
                string = MinimumFactory.setMinimumFt(ʼॱ);
                break;
            case 6:
                o_cke = cke.RESUME_DONWLOAD_APP;
                ʼॱ = sessionDownloadTask.ʼॱ();
                string = this.ˋ.getResources().getString(n.ॱˊ);
                break;
            case 7:
                o_cke = cke.MEGER_DIFF_APP;
                ʼॱ = 100;
                string = MinimumFactory.setMinimumFt(100);
                break;
            default:
                o_cke = cke.WAIT_DOWNLOAD_APP;
                ʼॱ = sessionDownloadTask.ʼॱ();
                string = MinimumFactory.setMinimumFt(ʼॱ);
                break;
        }
        o_ckg.ˋ(o_cke);
        o_ckg.ˏ(ʼॱ);
        o_ckg.ˊ(string.toUpperCase(Locale.getDefault()));
        return o_ckg;
    }

    @NonNull
    private ckg ˋ(BaseDistCardBean baseDistCardBean) {
        if (baseDistCardBean.ˈ()) {
            return ˊ(cke.DEPEND_GMS_APP, n.ॱˈ);
        }
        if (baseDistCardBean.ͺ() == 1) {
            return ˊ(cke.H5_APP, n.ॱˈ);
        }
        if (baseDistCardBean.ͺ() == 3) {
            return ˊ(cke.FAST_APP, n.ॱˈ);
        }
        if (ˊ(baseDistCardBean)) {
            return ˎ();
        }
        if (((cdg) cdb.ॱ(cdg.class)).ʽ(baseDistCardBean.ॱـ())) {
            return ˊ(cke.STOPED_APP, n.ॱˈ);
        }
        int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(baseDistCardBean.ॱـ());
        if (baseDistCardBean.ͺ() == 11 || baseDistCardBean.ͺ() == 12) {
            return ˏ(ˋ);
        }
        if (baseDistCardBean.ͺ() == 2) {
            return ˋ(ˋ, baseDistCardBean.ـ());
        }
        if (ʽ(baseDistCardBean)) {
            OrderAppCardBean orderAppCardBean = (OrderAppCardBean) baseDistCardBean;
            if (ˏ(baseDistCardBean, orderAppCardBean)) {
                return ˎ(orderAppCardBean);
            }
        }
        return ˎ(ˋ);
    }

    private boolean ॱ(BaseDistCardBean baseDistCardBean) {
        return (baseDistCardBean instanceof SafeAppCardBean) && baseDistCardBean.ͺ() == 14;
    }

    private boolean ˊ(BaseDistCardBean baseDistCardBean) {
        return ((baseDistCardBean instanceof SafeAppCardBean) || (baseDistCardBean instanceof AutoCompleteBtnCardBean)) && baseDistCardBean.ͺ() == 15;
    }

    private ckg ˎ() {
        return ˊ(cke.VAN_ATTEND_APP, n.ʼﹳ);
    }

    private ckg ॱॱ(BaseDistCardBean baseDistCardBean) {
        if (dcn.ˊ().ˊ(baseDistCardBean.v_())) {
            return ˊ(cke.WISH_APP_CHECK, n.ʼﹳ);
        }
        return ˊ(cke.WISH_APP_ADD, n.ـͺ);
    }

    @NonNull
    private ckg ˎ(int i) {
        if (3 == i) {
            return ˊ(cke.UPGRADE_APP, n.ॱʿ);
        }
        if (4 == i) {
            return ˊ(cke.SMART_UPGRADE_APP, n.ॱʿ);
        }
        if (1 == i) {
            return ˊ(cke.INSTALL_APP, n.ٴ);
        }
        if (2 == i) {
            return ˊ(cke.PRE_DOWNLAD_APP, n.ॱʿ);
        }
        if (10 == i) {
            return ˊ(cke.WAIT_INSTALL_APP, n.ꜞˋ);
        }
        if (11 == i) {
            return ˊ(cke.INSTALLING_APP, n.ꜞˋ);
        }
        if (12 == i) {
            return ˊ(cke.WAIT_UNINSTALL_APP, n.ˌ);
        }
        if (13 == i) {
            return ˊ(cke.UNINSTALLING_APP, n.ˊˋ);
        }
        if (i == 0) {
            return ˊ(cke.OPEN_APP, n.ॱˈ);
        }
        return ˊ(cke.DOWNLOAD_APP, n.ٴ);
    }

    private boolean ʽ(BaseDistCardBean baseDistCardBean) {
        return 4 == baseDistCardBean.ͺ() && (baseDistCardBean instanceof OrderAppCardBean);
    }

    private boolean ˏ(BaseDistCardBean baseDistCardBean, OrderAppCardBean orderAppCardBean) {
        PackageInfo ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ(baseDistCardBean.ॱـ());
        boolean z = !TextUtils.isEmpty(baseDistCardBean.ʾ());
        int ʽˊ = orderAppCardBean.ʽˊ();
        boolean z2;
        if (ᐝ == null || ᐝ.versionCode < ʽˊ) {
            z2 = false;
        } else {
            z2 = true;
        }
        if (z || r3) {
            return false;
        }
        return true;
    }

    @NonNull
    private ckg ˎ(OrderAppCardBean orderAppCardBean) {
        ckg o_ckg = new ckg();
        if (orderAppCardBean.ʼᐝ() == 1) {
            o_ckg.ˋ(cke.RESERVE_GAME_END);
            o_ckg.ˊ(this.ˋ.getResources().getString(n.ˈʻ));
        } else if (orderAppCardBean.ʿॱ() == 1) {
            o_ckg.ˋ(cke.RESERVED_GAME);
            o_ckg.ˊ(this.ˋ.getResources().getString(n.ॱʾ));
        } else {
            o_ckg.ˋ(cke.UNRESERVED_GAME);
            o_ckg.ˊ(this.ˋ.getResources().getString(n.ߺ));
        }
        return o_ckg;
    }

    private ckg ˊ(cke o_cke, int i) {
        ckg o_ckg = new ckg();
        o_ckg.ˋ(o_cke);
        o_ckg.ˊ(this.ˋ.getResources().getString(i));
        return o_ckg;
    }

    @NonNull
    private ckg ˏ(int i) {
        if (i == 3 || i == 4) {
            return ˊ(cke.NO_APK_APP, n.ߴ);
        }
        if (i == 0) {
            return ˊ(cke.OPEN_APP, n.ॱˈ);
        }
        if (12 == i) {
            return ˊ(cke.WAIT_UNINSTALL_APP, n.ˌ);
        }
        if (i == 13) {
            return ˊ(cke.UNINSTALLING_APP, n.ˊˋ);
        }
        return ˊ(cke.NO_APK_APP, n.ߴ);
    }

    @NonNull
    private ckg ˋ(int i, int i2) {
        ckg o_ckg = new ckg();
        if (i == 0 || i == 3 || i == 4) {
            o_ckg.ˋ(cke.OPEN_APP);
            o_ckg.ˊ(this.ˋ.getResources().getString(n.ॱˈ));
        } else {
            if (-1 == i2) {
                o_ckg.ˋ(cke.GOOGLE_PLAY);
            } else if (1 == i2) {
                o_ckg.ˋ(cke.DOWNLOAD_APP);
            } else if (2 == i2) {
                o_ckg.ˋ(cke.DEEPLINK_ORDER);
            }
            o_ckg.ˊ(this.ˋ.getResources().getString(n.ٴ));
        }
        return o_ckg;
    }

    public void ˏ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        if (this.ˏ != null) {
            this.ˏ.ˋ(context, downloadButton, baseDistCardBean, o_cke);
        } else {
            ॱ(context, downloadButton, baseDistCardBean, o_cke);
        }
    }

    private void ˎ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        if (ˋ(context, baseDistCardBean)) {
            switch (o_cke) {
                case APP_INVALIED:
                    Logger.e("DownloadButtonDelegate", "OnClick, status is APP_INVALIED");
                    return;
                case DOWNLOAD_APP:
                case SMART_UPGRADE_APP:
                case UPGRADE_APP:
                    ˏ(context, downloadButton, baseDistCardBean, o_cke);
                    return;
                case OPEN_APP:
                case DEPEND_GMS_APP:
                case STOPED_APP:
                    dkh.ॱ(downloadButton, baseDistCardBean);
                    return;
                case PRE_DOWNLAD_APP:
                case INSTALL_APP:
                    ˋ(context, downloadButton, baseDistCardBean, o_cke);
                    return;
                case WAIT_DOWNLOAD_APP:
                case PAUSE_DOWNLOAD_APP:
                    new dka(context, downloadButton, false, false, baseDistCardBean, new d(downloadButton)).ॱ();
                    return;
                case RESUME_DONWLOAD_APP:
                case RESERVE_DOWNLOAD_APP:
                    new dka(context, downloadButton, false, false, baseDistCardBean, new d(downloadButton)).ˊ();
                    return;
                default:
                    ˊ(context, downloadButton, baseDistCardBean, o_cke);
                    return;
            }
        }
    }

    private void ˊ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        switch (o_cke) {
            case H5_APP:
            case FAST_APP:
                ˎ(context, baseDistCardBean, o_cke);
                return;
            case GOOGLE_PLAY:
                djx.ˎ(context, baseDistCardBean.ॱॱ());
                Logger.ˎ("DownloadButtonDelegate", "launchGooglePlayApp " + new dkg().ˏ(context, baseDistCardBean.ॱـ(), baseDistCardBean.ˊॱ()));
                return;
            case DEEPLINK_ORDER:
                Logger.ˎ("DownloadButtonDelegate", "launch app result: " + new dkg().ˎ(context, baseDistCardBean.ॱͺ(), baseDistCardBean.ॱـ(), baseDistCardBean.ᐧ(), baseDistCardBean.ॱॱ()));
                return;
            case UNRESERVED_GAME:
                ॱ(context, downloadButton, baseDistCardBean);
                return;
            case RESERVED_GAME:
                ˎ(context, downloadButton, baseDistCardBean);
                return;
            case NOT_HUAWEI_VERSION:
                ˎ(context, downloadButton, baseDistCardBean, false, true);
                return;
            case NO_APK_APP:
                djx.ˎ(context, baseDistCardBean.ॱॱ());
                new ebt(context, baseDistCardBean).ˊ();
                return;
            case WISH_APP_ADD:
                djx.ˎ(context, baseDistCardBean.v_(), baseDistCardBean.ॱॱ());
                eny.ˊ().ˎ(context, baseDistCardBean.v_(), 13);
                return;
            case WISH_APP_CHECK:
                djx.ॱ(context, baseDistCardBean.v_(), baseDistCardBean.ॱॱ());
                eny.ˊ().ˊ(context);
                return;
            case VAN_ATTEND_APP:
                ˏ(context, (BaseCardBean) baseDistCardBean);
                return;
            default:
                return;
        }
    }

    private void ˏ(Context context, BaseCardBean baseCardBean) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        appDetailActivityProtocol.ˏ(new Request(baseCardBean.ॱॱ(), baseCardBean.u_()));
        cjk.ˎ().ˋ(context, new cjm("appdetail.activity", appDetailActivityProtocol));
    }

    private void ˎ(Context context, final BaseDistCardBean baseDistCardBean, final cke o_cke) {
        Object obj = (UserSession.getInstance().isUserMinor() && UserSession.getInstance().getUserAge() < baseDistCardBean.ʻॱ() && eqp.ᐝ()) ? 1 : null;
        if (obj != null) {
            new ewd(context, baseDistCardBean, o.ewd.e.OPEN_APP, new c(this) {
                final /* synthetic */ dkd ॱ;

                public void ˋ(Context context) {
                    this.ॱ.ˏ(context, baseDistCardBean, o_cke);
                }

                public void ˎ() {
                }
            }).ˋ();
        } else {
            ˏ(context, baseDistCardBean, o_cke);
        }
    }

    private void ˏ(Context context, BaseDistCardBean baseDistCardBean, cke o_cke) {
        if (o_cke == cke.H5_APP) {
            BaseCardBean baseCardBean = new BaseCardBean();
            baseCardBean.ॱ(baseDistCardBean.ॱˊ());
            cii.ˊ().ˊ(context, baseCardBean);
        } else if (o_cke == cke.FAST_APP) {
            ˏ(context, baseDistCardBean);
        }
    }

    private void ˏ(Context context, BaseDistCardBean baseDistCardBean) {
        if (baseDistCardBean == null) {
            Logger.ˎ("DownloadButtonDelegate", "The cardBean is null.");
        } else if (baseDistCardBean.detailType_ != 1) {
            ˊ(context, baseDistCardBean);
        } else if (dzz.ˏ(context, baseDistCardBean)) {
            new eaa(context, baseDistCardBean).ॱ(context);
        } else {
            ˊ(context, baseDistCardBean);
        }
    }

    private void ˊ(Context context, BaseDistCardBean baseDistCardBean) {
        djx.ˊ(baseDistCardBean.ॱॱ(), context);
        RpkInfo rpkInfo = new RpkInfo();
        rpkInfo.setPackageName(baseDistCardBean.ॱـ());
        FastSDKEngine.launchFastAppFromAppGallery(context, rpkInfo);
    }

    private void ˋ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        dki.ˊ(context, downloadButton, baseDistCardBean, o_cke);
        cki ʽ = downloadButton.ʽ();
        if (ʽ != null) {
            ʽ.ˋ();
        }
    }

    private void ˎ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean) {
        if (TextUtils.isEmpty(baseDistCardBean.ॱـ())) {
            Logger.ˋ("DownloadButtonDelegate", "performConfirm to cancel reserve error: packageName is empty");
            return;
        }
        cku ˏ = cku.ˏ(context, cku.class, null, context.getResources().getString(n.ͺˏ));
        ˏ.ˎ(context);
        ˏ.ॱ(-1, context.getString(n.ͺˎ));
        ˏ.ॱ(-2, context.getString(n.ˏͺ));
        ˏ.ॱ(new a(context, downloadButton, baseDistCardBean));
    }

    private void ॱ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean) {
        new dkj().ॱ(context, baseDistCardBean.ॱـ(), baseDistCardBean, new d(downloadButton));
        djx.ˎ(context, baseDistCardBean.ॱـ(), downloadButton);
        cki ʽ = downloadButton.ʽ();
        if (ʽ != null) {
            ʽ.ˋ();
        }
    }

    private boolean ˋ(Context context, BaseDistCardBean baseDistCardBean) {
        if (baseDistCardBean != null && context != null) {
            return true;
        }
        Logger.e("DownloadButtonDelegate", "OnClick, null param exception");
        return false;
    }

    public void ॱ(final Context context, final DownloadButton downloadButton, final BaseDistCardBean baseDistCardBean, cke o_cke) {
        dvt.ˏ().ˊ(baseDistCardBean.ॱـ());
        switch (o_cke) {
            case DOWNLOAD_APP:
                if (!dki.ˎ(context, baseDistCardBean)) {
                    ˎ(context, downloadButton, baseDistCardBean, true, true);
                    return;
                }
                return;
            case SMART_UPGRADE_APP:
            case UPGRADE_APP:
                dkl.ॱ(context, baseDistCardBean, o_cke, new b(this) {
                    final /* synthetic */ dkd ˏ;

                    public void ˏ(boolean z) {
                        boolean z2;
                        dkd o_dkd = this.ˏ;
                        Context context = context;
                        DownloadButton downloadButton = downloadButton;
                        BaseDistCardBean baseDistCardBean = baseDistCardBean;
                        if (z) {
                            z2 = false;
                        } else {
                            z2 = true;
                        }
                        o_dkd.ˎ(context, downloadButton, baseDistCardBean, z2, false);
                    }
                });
                return;
            default:
                return;
        }
    }

    private void ˎ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, boolean z, boolean z2) {
        if (TextUtils.isEmpty(baseDistCardBean.ॱـ())) {
            Logger.e("DownloadButtonDelegate", "the download app's packageName is null, which is illegal.");
            return;
        }
        Logger.ˎ("HiAppDownload", "download button clicked");
        new dka(context, downloadButton, !z, z2, baseDistCardBean, new d(downloadButton)).ˏ();
    }
}
